-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
--
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local m = {}
local log = require 'mc.logging'
local mdb_access = require 'route_mapper.mdb_access'

local TPCM_MICROCOMPONENT_PATH <const> = '/bmc/kepler/tpcm/MicroComponent'
local MICROCOMPONENT_INTF <const> = 'bmc.kepler.MicroComponent'

function m.get_tpcm_supported(tcm_precense)
    -- 若TCM不在位，则返回false
    if not tcm_precense then
        return false
    end

    -- TCM在位场景，则需要检查TPCM是否支持
    local ok, obj = pcall(function()
        return mdb_access.get_object(bus, TPCM_MICROCOMPONENT_PATH, MICROCOMPONENT_INTF)
    end)
    if not ok then
        log:info('Invalid Path, err: %s', obj)
        return false
    end

    return true
end

return m